'
' DotNetNuke Ita - http://dotnetnukeita.blogspot.com
' Daniele Lembo
'

Imports DotNetNuke
Imports System.Web.UI

Namespace DotNetNukeIta.Modules.RSSNuke

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The Settings class manages Module Settings
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Partial Class SettingsRSSNuke
        Inherits Entities.Modules.ModuleSettingsBase

#Region "Base Method Implementations"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' LoadSettings loads the settings from the Database and displays them
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Overrides Sub LoadSettings()
            Try

                If (Page.IsPostBack = False) Then

                    Dim li As ListItem
                    li = New ListItem(Format(Now, "MM/dd/yyyy h:mm:ss tt"), "MM/dd/yyyy h:mm:ss tt")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "MM/dd/yyyy H:mm:ss"), "MM/dd/yyyy H:mm:ss")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dd/MM/yyyy h:mm:ss tt"), "dd/MM/yyyy h:mm:ss tt")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dd/MM/yyyy H:mm:ss"), "dd/MM/yyyy H:mm:ss")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "MM/dd/yyyy h:mm tt"), "MM/dd/yyyy h:mm tt")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "MM/dd/yyyy H:mm"), "MM/dd/yyyy H:mm")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dd/MM/yyyy h:mm tt"), "dd/MM/yyyy h:mm tt")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dd/MM/yyyy H:mm"), "dd/MM/yyyy H:mm")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "MM/dd/yyyy"), "MM/dd/yyyy")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dd/MM/yyyy"), "dd/MM/yyyy")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "D"), "D")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "F"), "F")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "f"), "f")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dddd, dd MMMM, yyyy - H:mm:ss"), "dddd dd MMMM, yyyy  H:mm:ss")
                    ddlDateFormat.Items.Add(li)
                    li = New ListItem(Format(Now, "dddd, dd MMMM, yyyy - H:mm"), "dddd dd MMMM, yyyy  H:mm")
                    ddlDateFormat.Items.Add(li)

                    If CType(TabModuleSettings("rssfeeds"), String) <> "" Then
                        txtFeedURL.Text = CType(TabModuleSettings("rssfeeds"), String)
                    End If
                    If IsNumeric(TabModuleSettings("numOfFeeds")) Then
                        txtNumOfFeeds.Text = CType(TabModuleSettings("numOfFeeds"), Integer)
                    End If
                    If IsNumeric(TabModuleSettings("numOfDescrChars")) Then
                        txtNumOfDescrChars.Text = CType(TabModuleSettings("numOfDescrChars"), Integer)
                    End If
                    If Not TabModuleSettings("newWindow") Is Nothing Then
                        If TabModuleSettings("newWindow") <> "" Then
                            chkNewWindow.Checked = CType(TabModuleSettings("newWindow"), Boolean)
                        End If
                    End If
                    If CType(TabModuleSettings("dateFormat"), String) <> "" Then
                        li = ddlDateFormat.Items.FindByValue(CType(TabModuleSettings("dateFormat"), String))
                        ddlDateFormat.SelectedIndex = ddlDateFormat.Items.IndexOf(li)
                    End If

                    If IsNumeric(TabModuleSettings("imgW")) Then
                        txtImgW.Text = CType(TabModuleSettings("imgW"), Integer)
                    Else
                        txtImgW.Text = "200"
                    End If
                    If IsNumeric(TabModuleSettings("imgH")) Then
                        txtImgH.Text = CType(TabModuleSettings("imgH"), Integer)
                    Else
                        txtImgH.Text = "70"
                    End If
                    If IsNumeric(TabModuleSettings("imgCapW")) Then
                        txtImgCapW.Text = CType(TabModuleSettings("imgCapW"), Integer)
                    Else
                        txtImgCapW.Text = "600"
                    End If
                    If IsNumeric(TabModuleSettings("imgCapH")) Then
                        txtImgCapH.Text = CType(TabModuleSettings("imgCapH"), Integer)
                    Else
                        txtImgCapH.Text = "210"
                    End If
                End If
            Catch exc As Exception           'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' UpdateSettings saves the modified settings to the Database
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public Overrides Sub UpdateSettings()
            Try
                Dim objModules As New Entities.Modules.ModuleController
                Page.Validate()
                If Page.IsValid Then
                    objModules.UpdateTabModuleSetting(TabModuleId, "rssfeeds", txtFeedURL.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "numOfFeeds", txtNumOfFeeds.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "newWindow", chkNewWindow.Checked)
                    objModules.UpdateTabModuleSetting(TabModuleId, "numOfDescrChars", txtNumOfDescrChars.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "dateFormat", ddlDateFormat.SelectedValue)
                    objModules.UpdateTabModuleSetting(TabModuleId, "imgW", txtImgW.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "imgH", txtImgH.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "imgCapW", txtImgCapW.Text)
                    objModules.UpdateTabModuleSetting(TabModuleId, "imgCapH", txtImgCapH.Text)
                Else
                    ' Page not valid


                End If
                ' refresh cache
            Catch exc As Exception           'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then


            End If
        End Sub
    End Class

End Namespace


